home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 4 / Mac Giga-ROM 4.0 - 1993.toast / FILES / DEV / C-H / Hear Me! w:Demo.sit / Hear Me! / Hear Me!.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-18  |  6.4 KB  |  196 lines  |  [TEXT/KAHL]

  1. /*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *
  2. /*
  3. /*                            HEAR ME!
  4. /*
  5. /*                         by Joseph Laffey
  6. /*
  7. /*                          AOL: JoeLaff
  8. /*                         CIS: 70712,2306
  9. /*
  10. /*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *
  11. /*
  12. /*     This program will play a sound resource and put up nifty cursors.
  13. /*
  14. /*    Use freely to distribute HEAR ME!s with your programs or to friends.
  15. /*
  16. /*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *
  17. /*
  18. /*    Simply paste in your own 'snd ' resource with the appropriate id.
  19. /*
  20. /*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *
  21. /*
  22. /*    Make sure you allocate enough application memory for your 'snd ' resource!!
  23. /*
  24. /*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *
  25. */
  26.  
  27. #include <Sound.h>
  28. #include <GestaltEqu.h>
  29. #include <Types.h>
  30.  
  31. #define    VOLUME                7        /* The volume level (0-7) at which to play the sound */
  32. #define    SND_ID                17000    /* The resource id of the 'snd ' resource */
  33. #define    NIL_POINTER            0L        /* Nil pointer for passing to SndPlay routine */
  34. #define    SPEAKER_CURS_ID        401     /* The resource id of the speaker cursor */
  35. #define    EXIT_CURS_ID        501     /* The resource id of the "click to exit" cursor */
  36. #define    RED_CURS_ID            128        /* The resource id of the red square cursor */
  37. #define    YELLOW_CURS_ID        129        /* The resource id of the yellow square cursor */
  38. #define    BLACK_CURS_ID        129        /* The resource id of the black square cursor */
  39. #define    WHITE_CURS_ID        129        /* The resource id of the white square cursor */
  40. #define    BLINK_SPEED            2        /* The delay between cursor flashes */
  41. #define    NUM_BLINK            15        /* The number of times to blink the cursor */
  42.  
  43. void main( void )
  44. {
  45.     
  46.     SCStatus        soundStatus;        /*  the sound status */
  47.     SndChannelPtr    sndChannel;
  48.     Handle            theSnd;            /*  Holds the sound resource  */
  49.     short            theVol;            /*    Holds the current volume level for reset */
  50.     CCrsrHandle        theCCursor;        /*    Holds the color cursor resource  */
  51.     CCrsrHandle        theCCursor2;    /*    Holds the color cursor resource  */
  52.     CursHandle        theCursor;        /*    Holds the B&W cursor resource  */
  53.     CursHandle        theCursor2;        /*    Holds the B&W cursor resource  */
  54.     OSErr            theErr;            /*  Holds the errors result */
  55.     long            gestaltAnswer;    /*  Holds the gestalt answer */
  56.     Boolean            noQuit = TRUE;    /*  Stops the sound    */
  57.     int                i;                /*  Counter    */
  58.  
  59.  
  60. /**************/
  61.  
  62.     /** Check for Color QD **/
  63.     
  64.     theErr = Gestalt( gestaltQuickdrawVersion, &gestaltAnswer ); /* check for colorQD */
  65.     if( theErr )
  66.         ExitToShell();                /* quit if there is an error */
  67.     if( gestaltAnswer )   /* if the version is higher than 0 then Color QD is present */
  68.         {
  69.             theCCursor = GetCCursor( RED_CURS_ID );    /* load in the cursor resource */
  70.             if( ResError()  )
  71.             ExitToShell();                /* quit if there is an error */
  72.     
  73.             theCCursor2 = GetCCursor( YELLOW_CURS_ID );    /* load in the cursor resource */
  74.             if( ResError()  )
  75.             ExitToShell();                /* quit if there is an error */
  76.             
  77.             for( i = 0; i < NUM_BLINK; i++ )
  78.             {
  79.                 SetCCursor(theCCursor);        /* set the cursor */
  80.                 Delay( BLINK_SPEED, 0 );                /* delay for 2 tick counts (1/60ths of a sec.) */
  81.             
  82.                 SetCCursor(theCCursor2);        /* set the cursor */
  83.                 Delay( BLINK_SPEED, 0 );                /* delay for 2 tick counts (1/60ths of a sec.) */
  84.             
  85.             }
  86.             
  87.             
  88.             theCCursor = GetCCursor( SPEAKER_CURS_ID );    /* load in the cursor resource */
  89.             if( ResError()  )
  90.             ExitToShell();                /* quit if there is an error */
  91.     
  92.             SetCCursor(theCCursor);        /* set the cursor */
  93.         }
  94.         else
  95.         {
  96.             theCursor = GetCursor( SPEAKER_CURS_ID );    /* load in the cursor resource */
  97.             if( ResError()  )
  98.             ExitToShell();                /* quit if there is an error */
  99.             
  100.             theCursor2 = GetCursor( BLACK_CURS_ID );    /* load in the cursor resource */
  101.             if( ResError()  )
  102.             ExitToShell();                /* quit if there is an error */
  103.             
  104.             for( i = 0; i < NUM_BLINK; i++ )
  105.             {
  106.                 SetCursor(*theCursor);        /* set the cursor */
  107.                 Delay( BLINK_SPEED, 0 );                /* delay for 2 tick counts (1/60ths of a sec.) */
  108.             
  109.                 SetCursor(*theCursor2);        /* set the cursor */
  110.                 Delay( BLINK_SPEED, 0 );                /* delay for 2 tick counts (1/60ths of a sec.) */
  111.             }
  112.             
  113.             
  114.             
  115.             theCursor = GetCursor( WHITE_CURS_ID );    /* load in the cursor resource */
  116.             if( ResError()  )
  117.             ExitToShell();                /* quit if there is an error */
  118.             
  119.             SetCursor( *theCursor );    /* set the cursor */
  120.         }
  121.     
  122.     
  123.     /** Get and set the volume **/
  124.     
  125.     GetSoundVol( &theVol );            /* get the initial volume setting */
  126.     SetSoundVol( VOLUME );            /* set the volume to the desired level */
  127.     
  128.     /** Do the sound **/
  129.     
  130.     
  131.     sndChannel = (SndChannelPtr) NIL_POINTER;    /* Set the channel to Nil */
  132.     
  133.     theErr = SndNewChannel( &sndChannel, 0,             /* Allocate a new sound channel */
  134.             (long int) 0, (SndCallBackProcPtr) 0 );
  135.     if( theErr )
  136.         ExitToShell();                /* quit if there is an error */
  137.     
  138.     
  139.     theSnd = Get1Resource( 'snd ', SND_ID );    /* load in the sound resource */
  140.     if( ResError() )
  141.         ExitToShell();                        /* quit if there is an error */
  142.     
  143.     Delay(20, 0 );                    /* delay for 20 tick counts (1/60ths of a sec.) */
  144.     
  145.     
  146.     theErr = SndPlay( sndChannel, theSnd , TRUE );    /* play the sound asychronously */
  147.     if( theErr )
  148.         ExitToShell();                /* quit if there is an error */
  149.     
  150.     
  151.     theErr = SndChannelStatus( sndChannel,             /* get the sound channel status */
  152.                 sizeof( soundStatus ), &soundStatus );
  153.     if( theErr )
  154.             ExitToShell();                /* quit if there is an error */
  155.         
  156.         
  157.     
  158.         
  159.     while( noQuit && (soundStatus.scChannelBusy ) )
  160.         noQuit = !Button();                                /* Keep playing the sound unless
  161.                                                         there is a mouse click */
  162.                                                 
  163.     
  164.     /** ready to Quit **/
  165.  
  166.     if( gestaltAnswer )    /* if the version is higher than 0 then Color QD is present */
  167.         {
  168.             theCCursor = GetCCursor( EXIT_CURS_ID );    /* load in the cursor resource */
  169.             if( ResError()  )
  170.             ExitToShell();                /* quit if there is an error */
  171.     
  172.             SetCCursor(theCCursor);        /* set the cursor */
  173.         }
  174.         else
  175.         {
  176.             theCursor = GetCursor( EXIT_CURS_ID );    /* load in the cursor resource */
  177.             if( ResError()  )
  178.             ExitToShell();                /* quit if there is an error */
  179.             
  180.             SetCursor( *theCursor );    /* set the cursor */
  181.         }
  182.     
  183.     Delay( 50, 0 );                /* delay for 50 tick counts (1/60ths of a sec.) */
  184.     while( !Button() );                        /* wait for a click */
  185.     
  186.     theErr = SndDisposeChannel( sndChannel, TRUE );        /* Make sure the channel is silent */
  187.     
  188.     
  189.     SetSoundVol( theVol );                    /* reset the sound level */
  190.     ReleaseResource( theSnd );                /* release the sound resource */
  191.     ReleaseResource( theCCursor );            /* release the color cursor resource */
  192.     ReleaseResource( theCursor );            /* release the cursor resource */
  193.  
  194.     
  195.     
  196. }